//
// Created by fengg on 2020/3/13.
//

#include <iostream>
template <class T>
class Node{
private:
    T value;
    Node *LeftChild,*RightChild,*Parent;

public:
    explicit Node(T value){
        this->value = value;
        this->LeftChild = NULL;
        this->RightChild = NULL;
        this->Parent = NULL;
    }
    explicit Node(){
        this->LeftChild = NULL;
        this->RightChild = NULL;
        this->Parent = NULL;
    }
    Node(T value,Node* LChild,Node* RChild,Node* Parent){
        this->value = value;
        this->LeftChild = LChild;
        this->RightChild = RChild;
        this->Parent = Parent;
    }
    void setValue(T val){
        this->value = val;
    }
    T getValue(){
        return this->value;
    }

    Node* getLeftChild(){
        return this->LeftChild;
    }
    Node* getRightChild(){
        return this->RightChild;
    }
    Node* getParent(){
        return this->Parent;
    }
    void setLeftChild(Node *leftChild){
        this->LeftChild = leftChild;
    }
    void setRightChild(Node *rightChild){
        this->RightChild = rightChild;
    }
    void setParent(Node *parent){
        this->Parent = parent;
    }
};

template <class T>
class BinaryTree{
private:

    Node<T> *head;

public:
    BinaryTree(){
        this->head = new Node<T>();
    }
    Node<T>* getRoot(){
        return this->head;
    }

};

using namespace std;

enum  {
    Value = 0,
    LeftChild,
    RightChild
};

template <class T>
void
AddNode(Node<T> *Root,int id,int (*inputDate)[3]){
    Node<T> *LChild,*RChild;
    if( inputDate[id][LeftChild] != 0 ){
        LChild = new Node<T>(inputDate[inputDate[id][LeftChild]][Value]);
        AddNode(LChild,inputDate[id][LeftChild],inputDate);
        Root->setLeftChild(LChild);
        LChild->setParent(Root);
    }
    if( inputDate[id][RightChild] != 0 ){
        RChild = new Node<T>(inputDate[inputDate[id][RightChild]][Value]);
        AddNode(RChild,inputDate[id][RightChild],inputDate);
        Root->setRightChild(RChild);
        RChild->setParent(Root);

    }




}

template <class T>
T AvgSum(Node<T> *Root,int ){

}


int main(){
    int number=0;
    cin >> number;
    int (*inputDate)[3]= new int[number+1][3];
    for (int i = 1; i <= number; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> inputDate[i][j];
        }
    }

    BinaryTree<int> *binTree;
    binTree = new BinaryTree<int>();
    Node<int> *node =  binTree->getRoot();
    node->setValue(inputDate[1][Value]);
    AddNode<int>(node,1,inputDate);
    return 0;
}